﻿//using mediatr;
//using microsoft.identitymodel.tokens;
//using smartproduction.domain;
//using smartproduction.domain.yjh;
//using smartproduction.domain.客户管理;
//using smartproduction.domain.采购委外订单;
//using smartproduction.errorcode;
//using smartproduction.infarstructrue.interface;
//using smartproduction.read.api.application.commands.staskcommand__生产管理;
//using smartproduction.read.api.dto;
//using system.diagnostics;

//namespace smartproduction.read.api.application.commandhandlers.staskcommandhandler
//{
//    /// <summary>
//    /// 处理
//    /// </summary>
//    public class staskgetcommandhandler : irequesthandler<staskgetcommand, apiresult<apipaing<staskgetdto>>>
//    {
//        private readonly ibaserepository<stask> staskrepository;
//        private readonly ibaserepository<materiallist> materrepository;
//        private readonly ibaserepository<materialinfo> inforepository;
//        private readonly ibaserepository<processroute> processrepository;

//        /// <summary>
//        /// 构造方法
//        /// </summary>
//        /// <param name="staskrepository"></param>
//        public staskgetcommandhandler(ibaserepository<stask> staskrepository, ibaserepository<materiallist> materrepository, ibaserepository<materialinfo> inforepository, ibaserepository<processroute> processrepository)
//        {
//            this.staskrepository = staskrepository;//            this.materrepository = materrepository;

//            this.inforepository = inforepository;
//            this.processrepository = processrepository;
//        }
//        public async task<apiresult<apipaing<staskgetdto>>> handle(staskgetcommand request, cancellationtoken cancellationtoken)
//        {
//            apiresult<apipaing<staskgetdto>> result = new apiresult<apipaing<staskgetdto>>();
//            var entity = from a in staskrepository.getall().result
//                         join b in materrepository.getall().result on a.materiallistid equals b.materialid
//                         join c in inforepository.getall().result on a.materialserverid equals c.materialinfoid
//                         join d in processrepository.getall().result on a.processid equals d.processid
//                         where a.isdelete == 0
//                         select new staskgetdto
//                         {
//                             materialinfoname = c.materialinfoname,
//                             processname = d.processname,
//                             materialname = b.materialname,
//                             tid = a.tid,
//                             tasknode = a.tasknode,
//                             taskname = a.taskname,
//                             tasktype = a.tasktype,
//                             taskstatus = a.taskstatus,
//                             materiallistid = a.materiallistid,
//                             specification = a.specification,
//                             materialserverid = a.materialserverid,
//                             unit = a.unit,
//                             num = a.num,
//                             starttime = a.starttime,
//                             completiontime = a.completiontime,
//                             version = a.version,
//                             datastatus = a.datastatus,
//                             processid = a.processid,
//                             processver = a.processver,
//                             departid = a.departid,
//                         };
//            if (!string.isnullorempty(request.taskname))
//            {
//                entity = entity.where(x => x.taskname.contains(request.taskname));
//            }
//            if (!string.isnullorempty(request.tasknode))
//            {
//                entity = entity.where(x => x.tasknode.contains(request.tasknode));
//            }
//            if (request.taskstatus != null)
//            {
//                entity = entity.where(x => x.taskstatus == request.taskstatus);
//            }
//            if (request.materialserverid != 0)
//            {
//                entity = entity.where(x => x.materialserverid == request.materialserverid);
//            }
//            int totalcount = entity.count();
//            int pagecount = (int)math.ceiling(totalcount * 1.0 / request.pagesize);
//            entity = entity.orderbydescending(x => x.tid).skip((request.pageindex - 1) * request.pagesize).take(request.pagesize);

//            apipaing<staskgetdto> paing = new apipaing<staskgetdto>();
//            paing.totalcount = totalcount;
//            paing.pagecount = pagecount;
//            paing.items = entity.tolist();
//            result.code = apienums.查询成功;
//            result.msg = apienums.查询成功.tostring();
//            result.data = paing;
//            return await task.fromresult(result);
//        }
//    }
//}
